package com.hhdys.init;


import com.hhdys.constant.Env;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class DingChatInit{
	private static final Logger log= LogManager.getLogger(DingChatInit.class);

	static {
		init();
	}
	public static void init() {
		log.info("init config info======================begin");
		Properties properties=new Properties();
		try {
			properties.load(DingChatInit.class.getResourceAsStream("../../dingchat.properties"));
			initProperties(properties);
		} catch (FileNotFoundException e) {
			log.error("init properties error：file not found！！！", e);
		} catch (IOException e) {
			log.error("init properties error：file not found！！！", e);
		}
		
		log.info("init config info======================end");
	}
	
	private static void initProperties(Properties p){
		String corpId=p.getProperty("corpId");
		String corpSecret=p.getProperty("corpSecret");
		String accessTokenUrl=p.getProperty("accessTokenUrl");
		String qiyeMessageUrl=p.getProperty("qiyeMessageUrl");
		String agentId=p.getProperty("agentId");
		log.info("corpId:{} and corpSecret:{} or accessTokenUrl:{} ",corpId,corpSecret,accessTokenUrl);
		log.info("qiyeMessageUrl:{}",qiyeMessageUrl);
		log.info("agentId is :{}",agentId);
		Env.corpId=corpId;
		Env.corpSecret=corpSecret;
		Env.accessTokenUrl=accessTokenUrl;
		Env.agentId=agentId;
	}

}
